# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import json
from scrapy.pipelines.images import ImagesPipeline

class DoubanPipeline:
    # def open_file(self,spider):
    #     self.file = open('movie.txt','w',encoding='utf-8')

    def process_item(self, item, spider):
        info = f'{item.get("movie_name")},{item.get("movie_core")}\n'
        # self.file.write(info)
        with open('douban.txt', 'a', encoding='utf-8') as f:
            f.write(info)
        return item

    print("文件爬取完毕")
    # def close_file(self,spider):
    #     self.file.close()


class DouBiPipeline(ImagesPipeline):

    def file_path(self, item, spider):
        filename = item.get("img_name")
        return item

